// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
//
// Copyright (c) KALEIDOS INC

@use "refactor/common-refactor.scss" as deprecated;

// TODO: Legacy sass variables. We should remove them in favor of DS tokens.
$bp-max-1366: "(max-width: 1366px)";

$thumbnail-default-width: deprecated.$s-252; // Default width
$thumbnail-default-height: deprecated.$s-168; // Default width

.dashboard-grid {
  font-size: deprecated.$fs-14;
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0 deprecated.$s-16;
}

.grid-row {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: calc(deprecated.$s-12 + var(--th-width, #{$thumbnail-default-width}));
  width: 100%;
  gap: deprecated.$s-24;
}

.grid-item {
  align-items: center;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  margin: deprecated.$s-12 0;
  position: relative;
  text-align: center;

  a,
  button {
    width: 100%;
    font-weight: deprecated.$fw400;
  }
  button {
    background-color: transparent;
    border: none;
    padding: 0 deprecated.$s-6;
  }

  .grid-item-th {
    border-radius: deprecated.$br-8;
    text-align: initial;
    width: var(--th-width, #{$thumbnail-default-width});
    height: var(--th-height, #{$thumbnail-default-height});
    background-size: cover;
    overflow: hidden;

    img {
      object-fit: contain;
    }
  }

  &.dragged {
    border-radius: deprecated.$br-4;
    outline: deprecated.$br-4 solid var(--color-accent-primary);
    text-align: initial;
    width: calc(var(--th-width) + deprecated.$s-12);
    height: var(--th-height, #{$thumbnail-default-height});
  }

  &.overlay {
    border-radius: deprecated.$br-4;
    border: deprecated.$s-2 solid var(--color-accent-tertiary);
    height: 100%;
    opacity: 0;
    pointer-events: none;
    position: absolute;
    width: 100%;
    z-index: deprecated.$z-index-1;
  }

  &:hover .overlay {
    display: block;
    opacity: 1;
  }

  .info-wrapper {
    display: grid;
    grid-template-columns: 1fr auto;
    cursor: pointer;
    max-width: var(--th-width, $thumbnail-default-width);
  }

  .item-info {
    display: grid;
    padding: deprecated.$s-8;
    text-align: left;
    width: 100%;
    font-size: deprecated.$fs-12;

    h3 {
      border: deprecated.$s-1 solid transparent;
      color: var(--color-foreground-primary);
      font-size: deprecated.$fs-16;
      font-weight: deprecated.$fw400;
      height: deprecated.$s-28;
      line-height: 1.92;
      max-width: deprecated.$s-260;
      overflow: hidden;
      padding-right: deprecated.$s-8;
      padding: 0;
      text-overflow: ellipsis;
      white-space: nowrap;
      width: 100%;

      @media #{$bp-max-1366} {
        max-width: deprecated.$s-232;
      }
    }

    .date {
      color: var(--color-foreground-secondary);
      overflow: hidden;
      text-overflow: ellipsis;
      width: 100%;
      white-space: nowrap;
      max-width: deprecated.$s-260;
      &::first-letter {
        text-transform: capitalize;
      }
      @media #{$bp-max-1366} {
        max-width: deprecated.$s-232;
      }
    }
  }

  .item-badge {
    background-color: var(--color-accent-primary);
    border: none;
    border-radius: deprecated.$br-6;
    position: absolute;
    top: deprecated.$s-12;
    right: deprecated.$s-12;
    height: deprecated.$s-32;
    width: deprecated.$s-32;
    display: flex;
    align-items: center;
    justify-content: center;

    svg {
      stroke: var(--color-background-secondary);
      fill: none;
      height: deprecated.$s-16;
      width: deprecated.$s-16;
    }
  }

  &.add-file {
    border: deprecated.$s-1 dashed var(--color-foreground-secondary);
    justify-content: center;
    box-shadow: none;

    span {
      color: var(--color-background-primary);
      font-size: deprecated.$fs-14;
    }

    &:hover {
      background-color: var(--color-foreground-primary);
      border: deprecated.$s-2 solid var(--color-accent-tertiary);
    }
  }
}

.drag-counter {
  position: absolute;
  top: deprecated.$s-4;
  left: deprecated.$s-4;
  width: deprecated.$s-32;
  height: deprecated.$s-32;
  background-color: var(--color-accent-tertiary);
  border-radius: deprecated.$br-circle;
  color: var(--color-background-secondary);
  font-size: deprecated.$fs-16;
  display: flex;
  justify-content: center;
  align-items: center;
}

// PROJECTS, ELEMENTS & ICONS GRID
.project-th {
  background-color: transparent;
  border-radius: deprecated.$br-8;
  padding-top: deprecated.$s-6;

  &:hover,
  &:focus,
  &:focus-within {
    background-color: var(--color-background-tertiary);
    .project-th-actions {
      opacity: 1;
    }
    a {
      text-decoration: none;
    }
  }

  .selected {
    .grid-item-th {
      outline: deprecated.$s-4 solid var(--color-accent-tertiary);
    }
  }
}

.project-th-actions {
  align-items: center;
  display: flex;
  height: 100%;
  justify-content: center;
  opacity: 0;
  right: deprecated.$s-6;
  width: deprecated.$s-32;

  span {
    color: var(--color-background-secondary);
  }
}

.project-th-icon {
  align-items: center;
  display: flex;
  margin-right: deprecated.$s-8;
  margin-top: 0;
}

.menu {
  align-items: flex-end;
  display: flex;
  flex-direction: column;
  height: deprecated.$s-32;
  justify-content: center;
  margin-right: 0;
  margin-top: deprecated.$s-20;
  width: 100%;
  --menu-icon-color: var(--button-tertiary-foreground-color-rest);

  &:hover,
  &:focus {
    --menu-icon-color: var(--button-tertiary-foreground-color-hover);
  }
}

.menu-icon {
  stroke: var(--menu-icon-color);
  fill: none;
  margin-right: 0;
  height: deprecated.$s-16;
  width: deprecated.$s-16;
}

.project-th-actions.force-display {
  opacity: 1;
}

.grid-item-th {
  border-radius: deprecated.$br-4;
  cursor: pointer;
  height: 100%;
  overflow: hidden;
  position: relative;
  width: 100%;
  display: flex;
  justify-content: center;
  flex-direction: row;

  .img-th {
    height: auto;
    width: 100%;
  }
}

// LIBRARY VIEW
.library {
  height: deprecated.$s-580;
}

.grid-item.project-th.library {
  height: deprecated.$s-612;
}

.grid-item-th.library {
  background-color: var(--color-background-tertiary);
  flex-direction: column;
  height: 90%;
  justify-content: flex-start;
  max-height: deprecated.$s-580;
  padding: deprecated.$s-32;

  .asset-section {
    font-size: deprecated.$fs-12;
    color: var(--color-foreground-secondary);

    &:not(:first-child) {
      margin-top: deprecated.$s-16;
    }
  }

  .asset-title {
    display: flex;
    font-size: deprecated.$fs-12;
    text-transform: uppercase;

    .num-assets {
      color: var(--color-foreground-secondary);
    }
  }

  .asset-list-item {
    align-items: center;
    border-radius: deprecated.$br-4;
    border: deprecated.$s-1 solid transparent;
    color: var(--color-foreground-primary);
    display: flex;
    font-size: deprecated.$fs-12;
    margin-top: deprecated.$s-4;
    padding: deprecated.$s-2;
    position: relative;

    .name-block {
      color: var(--color-foreground-secondary);
      width: calc(100% - deprecated.$s-24 - deprecated.$s-8);
    }

    .item-name {
      display: block;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }

    svg {
      background-color: var(--color-canvas);
      border-radius: deprecated.$br-4;
      border: deprecated.$s-2 solid transparent;
      height: deprecated.$s-24;
      margin-right: deprecated.$s-8;
      width: deprecated.$s-24;
    }

    .color-name {
      color: var(--color-foreground-primary);
    }

    .color-value {
      color: var(--color-foreground-secondary);
      margin-left: deprecated.$s-4;
      text-transform: uppercase;
    }

    .typography-sample {
      height: deprecated.$s-20;
      margin-right: deprecated.$s-4;
      width: deprecated.$s-20;
    }
  }
}

.color-item {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: deprecated.$s-8;
}

.grid-loader {
  --icon-width: calc(var(--th-width, #{$thumbnail-default-width}) * 0.25);
}
